package com.rem.rabbitmq.boot.Elazy;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author Rem
 * @date 2021-12-30
 */

@Slf4j
@RestController
@RequestMapping("/lazy")
@Api(tags = "惰性队列")
public class LazyController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ApiOperation(value = "发送一条的消息")
    @GetMapping("/sendMsg/{message}")
    public void sendMsg(@PathVariable String message) {
        log.info("当前时间：{}，发送消息开始:{}", LocalDateTime.now(), message);
        rabbitTemplate.convertAndSend(LazyConfig.LAZY_EXCHANGE, LazyConfig.LAZY_ROUTING_KEY, message);
        log.info("当前时间：{}，发送消息完毕:{}", LocalDateTime.now(), message);
    }


}
